<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>保证金管理列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<!-- 是否显示提交按钮 -->
<sys:funcAuth resCd="SplSubmit">
	<span id="isShowCmtBtn" ></span>
</sys:funcAuth>
<!-- 是否显示审核按钮 -->
<sys:funcAuth resCd="SplCheck">
	<span id="isShowAudBtn" ></span>
</sys:funcAuth>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
          <div class="fieldBox" >
              <div class="label">融资机构</div>
              <%-- <div class="field">
                 <select name="fncInsId" id="fncInsId" data-value="" validate="{required:true}">
                   <option value="" selected="selected">请选择</option>
                   <c:forEach items="${friBaseInfoList }" var="kv">
                       <option value="${kv.value}">${kv.key}</option>
                   </c:forEach>
                 </select>
              </div> --%>
              <div class="field">
                    <input name="fncInsId" id="fncInsId" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
                <div style="display: none">
              </div>
          </div> 
         <div class="fieldBox">
                <div class="label">项目名称</div>
                <div class="field">
                   <input name="fncPrjNm" id="fncPrjNm" type="text" class="ui-textbox" value="">
                </div>
            </div> 
            <div class="fieldBox">
                <div class="label">付款时间</div>
                <div class="field">
                   <input name="payTmMin" id="payTmMin" type="text" class="ui-datepicker" value="" >
                   <span>—</span>
                   <input name="payTmMax" id="payTmMax" type="text" class="ui-datepicker" value="" >
                </div>
            </div>
          <div class="btnsBox formBtns notRight">
              <span id="searchBtn" class="sq-button-round">查询</span>
              <span id="clearBtn" class="sq-button-round">清空</span>
              <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
          </div>
         </div>
       </form>
    </div>
</div>
<div id="mrgnligergrid" class="sq-grid"></div>
 <br> 
 <div style="display:none;"></div>
<script type="text/javascript">
	var grid = null;
	$(function () {
		 initcombobox();//融资机构初始化 add by gengchunlan 20190606
		 f_showMrgnManageInfo();
		 grid = liger.get("mrgnligergrid");
		 grid.setHeight(100);
		 $("#searchBar").ligerForm();
		 
		 $("#searchBtn").click(function(event) {
		        var form = new liger.get("searchBar");
		        var data = form.getData();
		        for (var name in data){
		           grid.setParm(name,data[name]);
		        };
		       grid.reload();
		   });
		   
		   $("#clearBtn").click(function(event) {
		       $("#resetBtn").click();  //重置 input-text
		       var form = liger.get("searchBar");
		       form.setData({  //重置select等特殊表单
		            "fncInsId": "" ,
		            "fncPrjNm": "" ,
		            "payTmMin": "" ,
		            "payTmMax": "" 
		       });
		   });
	});
	
	 //显示List
    function f_showMrgnManageInfo()
    {   var _url = '<%=path%>/rfbase/mrgnmanageinfo/initList.do';
	    $("#mrgnligergrid").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
                  { display: '状态', name: 'showColor', width: 60 , align:'center', 
   	            	render: function (rowdata, rowindex, value, column) { 
  	                	var imgpath = '';
  	                	if(rowdata.showColor =="green"){
  	                		imgpath = '<%=path%>/resource/lib/images/greenpoticon.png';
  	                	}else if(rowdata.showColor =="yellow"){
  	                		imgpath = '<%=path%>/resource/lib/images/goldenpoticon.png';
  	                	}else if(rowdata.showColor =="red"){
  	                		imgpath = '<%=path%>/resource/lib/images/redpoticon.png';
  	                	}
  		                return '<img alt="" width="20px" height="20px" src="'+imgpath+'">';
              	}},    
	            { display: '金融机构', name: 'fncInsNm', width: 150},
	            { display: '项目编号', name: 'fncPrjId', width: 150},
	            { display: '项目名称', name: 'fncPrjNm', width: 150},
	            { display: '融资方案', name: 'fncScmNm', width: 150},
	            { display: '已付保证金金额', name: 'mrgnAtm', width: 100 , render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
        	    { display: '保证金剩余金额', name: 'srplsMrgn', width: 100 , render: function (rowdata, rowindex, value, column) { 
  	            	var money =moneyChange(value);
                      return money;
              		},
          	      enabledSort:true}, 
	            { display: '创建时间', name: 'payTm', width: 150, render:renderDate},
	            { display: '计划退回时间', name: 'reReturnTm', width: 150, render:renderDate},
	            { display: '操作', width: 280 , align:'left',
	           
	            	render: function (rowdata, rowindex, value){
	            		//详情
	            		var repaymentInfo ='<a class="sq-button-hasicon" href="javascript:mrgnAtmDetail(';
	            	    	repaymentInfo +="'"+rowdata.id+"'";
	            	    	repaymentInfo +=')"><i class="sqBtnIco_4"></i>详情</a>';
	            		//坐扣
	            		var deductInfo ='<a class="sq-button-hasicon" href="javascript:deductOprt(';
	            		    deductInfo +="'"+rowdata.id+"'";
	            		    deductInfo +=')"><i class="sqBtnIco_4"></i>坐扣</a>';
	            		//退回
	            		var returnInfo ='<a class="sq-button-hasicon" href="javascript:returnOprt(';
	            			returnInfo +="'"+rowdata.id+"'";
	            			returnInfo +=')"><i class="sqBtnIco_4"></i>退回</a>';
	            	  
	            	    if(rowdata.srplsMrgn==null||rowdata.srplsMrgn==""||rowdata.srplsMrgn==0){
	            	    	return repaymentInfo;
	            	    }else{
	            	    	if(rowdata.mrgnSt==11){
		            			return repaymentInfo +' ' +'<a class="sq-button-hasicon" href="javascript:void(0)"><i class="sqBtnIco_4"></i>坐扣中</a>';
		            		}
		            		else if(rowdata.mrgnSt==12){
		            			return repaymentInfo+' ' +'<a class="sq-button-hasicon" href="javascript:void(0)"><i class="sqBtnIco_4"></i>保证金退回中</a>';
		            		}else{
		            			if(rowdata.fncPrjStCd==13||rowdata.fncPrjStCd==14){
			            			return repaymentInfo + " " + returnInfo;
			            		}else{
			            			return repaymentInfo +" " + deductInfo +" " + returnInfo;
			            		}
		            		}
	            	    }
	            	}
	            }
	        ],
	        pageSize:10, 
	        root:'rows',
	        record:'total',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:false,
	        rownumbers:true,
	    });
    }
	 
 	 //还款表
	function mrgnAtmDetail(_id){
		var lgcId=_id;
		Add_navTab('PrdSpl_1'+_id,'保证金详情','<%=path%>/rfbase/mrgnmanageinfo/toMrgnDetailInfoPage.do?lgcId='+lgcId);
	}
	
	//坐扣
	function deductOprt(_id){
		var prjLgcSn=_id;
		 $.ajax({
		   		type: 'GET',
		   		dataType:'json', 
		   		url: '<%=path%>/rfbase/mrgnmanageinfo/getRepayMainStByPrjId.do?prjLgcSn='+prjLgcSn,
		   		beforeSend: function(){
		   	       wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		   	     },
		   		success:function(msg){
		   			 wait_dialog.close();
		   			 var e=msg.success;
		   			 if(msg.success == 1){
		   				var fncPrjPaySchMVO=msg.data;
		   				if(fncPrjPaySchMVO.repayStcd!=2){
		   					Add_navTab('PrdSpl_2'+_id,'保证金坐扣','<%=path%>/rfbase/mrgnmanageinfo/toDeductOprtPage.do?prjLgcId='+prjLgcSn);
						 }else{
							$.ligerDialog.error("该项目正在还款中,无法同时发起坐扣！");
						 }
		   			 }else{
		   				 $.ligerDialog.error("无法判断该项目是否正在还款");
		   			 }
		   		}
		     });
	}
	
	 //退回
	function returnOprt(_id){
		if(!_id)return;
		var lgcId=_id;
		Add_navTab('PrdSpl_3'+_id,'保证金退回','<%=path%>/rfbase/mrgnmanageinfo/toReturnOprtPage.do?lgcId='+lgcId);
	} 
	 
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
	//格式化金额
	 function moneyChange(value) { 
			var h = '';
				if(value&&value!="null"){
			    h+=fmoney(value, 2);
				}else{
				h+="0.00";
				}
	         return h;
			}
	 
	 //格式化金额
	 function fmoney(s, n)   
		{   
		   n = n > 0 && n <= 20 ? n : 2;   
		   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
		   var l = s.split(".")[0].split("").reverse(),   
		   r = s.split(".")[1];   
		   t = "";   
		   for(i = 0; i < l.length; i ++ )   
		   {   
		      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
		   }   
		   return t.split("").reverse().join("") + "." + r;   
		} 
	 //初始化融资机构 by gengchunlan 20190606
	 var frilist = [];
	<c:if test="${not empty frilist}"> frilist = ${frilist}; </c:if>
	 function initcombobox(){
		 var combobox=  $("#fncInsId").ligerComboBox({
    	     data:frilist,
             selectBoxWidth: 270,
             selectBoxHeight: 150,
             valueField: "id",
             textField: "fundRasInsNm",
             autocomplete: function (e){
                 filter_autoComboboxData(e.key, this);
                 e.show();
             }

             
          });
	 }//end 
</script>
</body>
</html>